package tx.bjdacp.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.annotation.Rollback;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.junit.Test;

import cn.org.rapid_framework.test.context.TestMethodContext;
import static junit.framework.Assert.*;

import java.util.*;

import javacommon.base.*;
import javacommon.util.*;

import cn.org.rapid_framework.util.*;
import cn.org.rapid_framework.web.util.*;
import cn.org.rapid_framework.page.*;
import cn.org.rapid_framework.page.impl.*;

import tx.bjdacp.model.*;
import tx.bjdacp.dao.*;
import tx.bjdacp.service.*;
import tx.bjdacp.vo.query.*;


public class TotalCatalogManagerTest extends BaseManagerTestCase{

	protected Log log = LogFactory.getLog(getClass());
	private ArchiveCatalogManager ac_manager;

	@Autowired
	public void setArchiveCatalogManager(ArchiveCatalogManager ac_manager) {
		this.ac_manager = ac_manager;
	}

	private TotalCatalogManager manager;

	@Autowired
	public void setTotalCatalogManager(TotalCatalogManager manager) {
		this.manager = manager;
	}

    @Override
    protected String[] getDbUnitDataFiles() {
        //通过 TestMethodContext.getMethodName() 可以得到当前正在运行的测试方法名称
        return new String[]{"classpath:testdata/common.xml","classpath:testdata/TotalCatalog.xml",
                            "classpath:testdata/TotalCatalog_"+TestMethodContext.getMethodName()+".xml"};
    }

    /**
     * 初始化药监档案总目录数据，关联到对应的药监档案案卷目录
     */
    @Test
    @Rollback(false)
    public void initData(){
    	List<TotalCatalog> tcs=manager.findAll();
    	for (TotalCatalog totalCatalog : tcs) {
    		ArchiveCatalog ac=ac_manager.findByFileNumber(totalCatalog.getBoxNum());
    		if(ac!=null){
    			totalCatalog.setArchiveCatalogId(ac.getArchiveCatalogId());
    			manager.update(totalCatalog);
    		}
		}

    }

	//数据库单元测试前会开始事务，结束时会回滚事务，所以测试方法可以不用关心测试数据的删除

	public void crud() {

		TotalCatalog obj = newTotalCatalog();
		manager.save(obj);
		manager.getEntityDao().flush();

		manager.update(obj);
		manager.getEntityDao().flush();

		assertNotNull(obj.getTotalCatalogId());

		manager.removeById(obj.getTotalCatalogId());
		manager.getEntityDao().flush();

	}

	public static TotalCatalog newTotalCatalog() {
		TotalCatalog obj = new TotalCatalog();

	  	obj.setArchiveCatalogId(new java.lang.Integer("1"));
	  	obj.setSeqNum(new java.lang.Integer("1"));
	  	obj.setCatalogName(new java.lang.String("1"));
	  	obj.setYear(new java.lang.String("1"));
	  	obj.setPageNum(new java.lang.String("1"));
	  	obj.setBoxNum(new java.lang.String("1"));
	  	obj.setShenpiNum(new java.lang.String("1"));
	  	obj.setCatalogNum(new java.lang.String("1"));
		return obj;
	}
}
